package com.gylang.print.richtext.processor;

import com.gylang.print.richtext.Coords;
import com.gylang.print.richtext.pdf.RichPdfRender;
import com.gylang.print.richtext.resolver.StyleResolver;
import com.gylang.print.richtext.component.RichBox;
import com.gylang.print.richtext.component.BaseRichBr;
import com.gylang.print.richtext.component.BaseRich;
import org.jsoup.nodes.Element;

import java.util.List;

/**
 * @author gylang
 * data 2021/7/13
 */
public class BrProcessor implements StyleResolver, RichPdfRender<BaseRichBr> {
	@Override
	public boolean resolve(Element element, List<BaseRich> component, BaseRich parent) {
		if ("br".equalsIgnoreCase(element.tagName())) {
			BaseRichBr richBr = new BaseRichBr();
			richBr.copyStyle(parent);
			component.add(richBr);
			return true;
		}
		return false;
	}

	@Override
	public Coords render(Coords lastNodeCoords, RichBox box, BaseRichBr richBr) {

		// 换行
		return Coords.of(0, lastNodeCoords.getY() - 2 * box.getHeightLine() * box.getFontSize());
	}
}
